package org.cjlm.impl;

import org.cjlm.dao.SuperDao;
import org.cjlm.itf.TemplateDAO;
import org.cjlm.vo.SuperVO;
import org.cjlm.vo.template.TemplateAVO;
import org.cjlm.vo.template.TemplateActionVO;
import org.cjlm.vo.template.TemplateBVO;
import org.cjlm.vo.template.TemplateMVO;

import java.util.List;

public class TemplateDAOImpl implements TemplateDAO {
    @Override
    public TemplateMVO queryByPk(TemplateMVO queryVO) throws Exception {
        SuperDao dao = new SuperDao();
        TemplateMVO mvo = dao.queryById(queryVO);
        TemplateAVO qavo = new TemplateAVO(); qavo.setMid(mvo.getPrimaryKeyValue());
        List<SuperVO> avolist = dao.query(qavo);
        if(avolist != null && avolist.size() > 0){
            mvo.setChildren(avolist);
            for(SuperVO avo : avolist){
                TemplateBVO qbvo = new TemplateBVO(); qbvo.setAid(avo.getPrimaryKeyValue());
                List<SuperVO> bvolist = dao.query(qbvo);
                avo.addChildren(bvolist);

                TemplateActionVO qaction = new TemplateActionVO(); qaction.setAid(avo.getPrimaryKeyValue());
                List<SuperVO> actionlist = dao.query(qaction);
                avo.addChildren(actionlist);
            }
        }
        return mvo;
    }
}
